package com.tanhua.server.controller;

import com.tanhua.model.domain.UserInfo;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author Xiao
 * @date 2021/10/22
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 首次登陆-完善资料
     * @param userInfo  请求体
     * @param token 请求头
     * @return
     */
    @PostMapping("/loginReginfo")
    public ResponseEntity loginReginfo(
            @RequestBody UserInfo userInfo,
            @RequestHeader("Authorization") String token) {
        userInfoService.save(userInfo, token);
        return ResponseEntity.ok("添加成功！");
    }

    /**
     * 首次登录-补充头像
     * @param headPhoto
     * @param token
     * @return
     */
    @PostMapping("/loginReginfo/head")
    public ResponseEntity head(
            MultipartFile headPhoto,
        @RequestHeader("Authorization") String token) throws IOException {
        userInfoService.updateHead(headPhoto);
        return ResponseEntity.ok("头像上传成功！");
    }
}
